<%@ include file="/taglibs.jsp"%>
<jsp:directive.page import="redstone.xmlrpc.XmlRpcClient"/>
<jsp:directive.page import="redstone.xmlrpc.XmlRpcStruct"/>
<jsp:directive.page import="net.spy.memcached.*"/>
<jsp:directive.page import="java.net.InetSocketAddress"/>
<%
Integer blog_ID = 1;

String sXmlRpcMethod = "wp.getPage";
String pageID = (request.getParameter("pageID"));
XmlRpcStruct struct = null;
String content = "";
String title = "";

// Try block
	MemcachedClient cacheClient = new MemcachedClient(new InetSocketAddress("localhost", 11211));
	content = (cacheClient.get("contentPage_" + pageID) != null) ? cacheClient.get("contentPage_" + pageID).toString() : "";
	title = (cacheClient.get("titlePage_" + pageID) != null) ? cacheClient.get("titlePage_" + pageID).toString() : "";
	if(content.equals("")){
		try {
			// Create the XML-RPC client
			XmlRpcClient client = new XmlRpcClient( "http://static.winterwar.org/blog/xmlrpc.php", true);
			
			// Make our method call
			Object token = client.invoke( sXmlRpcMethod, new Object[] {  blog_ID, pageID, "admin", "C0nv3nt10n" } );
			struct = (XmlRpcStruct)token;
			content = struct.getString("description");
			title = struct.getString("title");
			cacheClient.set("contentPage_" + pageID, 86400, content);
			cacheClient.set("titlePage_" + pageID, 86400, title);
		}
		
		// Catch exceptions
		catch( Exception e ){
		  // error output?
		}
	}
if(pageID != null){
%>
<title>Winter War Gaming Convention - <%=title %></title>

<%= content %>

<%} else {%>
Nothing.
<%}%>